Music Object Instance Methods
|
|
In the table below, the Music Object instance methods are divided into groups based upon the areas of functionality that they relate to. You can click on a method's name to get detailed information for that method, or you can click on one of the group headings to start reading in detail about that group of methods.
| Method Name |
Short Description |
| Embedding |
| magicEmbed |
Lets you embed a player instance in an HTML page, so that the player instance can be controlled using the Music Object API. |
| preloadEmbed |
Lets you preload a music file into a hidden player instance, for the purpose of triggering the file to play at a later point. |
| stubEmbed |
Lets you preload a stub RMF file into a hidden player instance, specifically for the purpose of playing musical notes through that instance. |
| Song Control & Player Properties |
| doMenuItem |
Lets you emulate the user-selection of one of the control panel's pop-up menu options. |
| endVolumeFade |
Lets you terminate any volume fade that is currently in progress for a Music Object instance. |
| fadeTo |
Lets you fade the overall playback volume of the Music Object instance from its current volume level to a new specified volume level, over the specified amount of time. |
| fadeVolume |
Lets you fade the overall playback volume of the Music Object instance from a specified starting volume to a specified ending volume over a specified amount of time. |
| getAutostart |
Returns the autostart property of the Music Object instance. |
| getFileSize |
Returns the size of the currently loaded file, measured in bytes. |
| getPanelDisplay |
Returns a string value, indicating the Music Object instance's current control panel display type. |
| getPanelMode |
Returns a string value, indicating the Music Object instance's current control panel mode. |
| getPlayLength |
Returns the playing duration of the currently loaded file, measured in milliseconds. |
| getPosition |
Returns an integer value, indicating the currently playing file's song position. |
| pause |
Lets you pause the file that is currently being played through the Music Object instance, so that it may be resumed later. |
| play |
Lets you start a file playing that is currently loaded into a Music Object instance, or load or play a different music file than the file that is currently loaded by specifying a file URL. |
| setAutostart |
Lets you set the autostart property of the Music Object instance. |
| setEndTime |
Lets you specify the position in an RMF or MIDI file where you would like playback to stop automatically. |
| setLoop |
Lets you set the loop status of the Music Object instance. |
| setPanelDisplay |
Lets you set the control panel display type of the Music Object instance. |
| setPanelMode |
Lets you set the control panel mode of the Music Object instance. |
| setPosition |
Lets you jump to a new position in the music file that is currently being played by the Music Object instance. |
| setStartTime |
Lets you specify the position in an RMF or MIDI file, where you would like playback to start. |
| setVolume |
Lets you set the overall playback volume of the Music Object instance. |
| stop |
Lets you stop any file that is currently playing through the Music Object instance. |
| Note Playing |
| noteOff |
Lets you turn off a note that is currently playing through the Music Object instance. |
| noteOn |
Lets you start a note playing on a specified MIDI channel number, with a specified note number and velocity. |
| playNote |
Lets you play a note on the specified MIDI channel, of the specified note number, velocity, and duration. |
| Realtime Control |
| setChannelMute |
Lets you mute or unmute the specified MIDI channel. |
| setChannelSolo |
Lets you solo or unsolo the specified MIDI channel. |
| setController |
Lets you set a value for a specified MIDI controller on a specified MIDI channel. |
| setMonophonic |
Lets you set the monophonic state of a specified MIDI channel. |
| setProgram |
Lets you issue a program change message to the specified MIDI channel with the specified program number. |
| setTempo |
Lets you set the tempo (playback speed) of the music file that is playing through the Music Object instance. |
| setTrackMute |
Lets you mute or unmute the specified track. |
| setTrackSolo |
Lets you solo or unsolo the specified track. |
| setTransposable |
Lets you set whether or not the specified MIDI channel in an RMF or MIDI file is transposable. |
| setTranspose |
Lets you set the pitch transposition of the file that is currently playing through the Music Object instance. |
| Playback State |
| isPaused |
Returns a boolean value, indicating the current paused state of the Music Object instance. |
| isPlaying |
Returns a boolean value, indicating the current playing state of the Music Object instance. |
| getChannelMute |
Returns a boolean value, indicating the current mute status of the specified MIDI channel. |
| getChannelSolo |
Returns a boolean value, indicating the current solo status of the specified MIDI channel. |
| getController |
Returns an integer value, indicating the current value of the specified MIDI controller on the specified MIDI channel. |
| getLoop |
Returns a boolean value, indicating the current loop status of the Music Object instance. |
| getMonophonic |
Returns a boolean value, indicating the monophonic state of the specified MIDI channel. |
| getOutputVolume |
Returns an integer value, indicating the current overall output volume of the Music Object instance. |
| getProgram |
Returns an integer value, indicating the program number that is currently selected for the specified MIDI channel. |
| getTempo |
Returns an integer value, indicating the current tempo (playback speed) of the file that is playing through the Music Object instance. |
| getTrackMute |
Returns a boolean value, indicating the current mute status of the specified track. |
| getTrackSolo |
Returns a boolean value, indicating the current solo status of the specified track. |
| getTransposable |
Returns a boolean value, indicating whether or not the specified MIDI channel will be affected by the Music Object instance's transposition value |
| getTranspose |
Returns an integer value, indicating the current pitch transposition of the Music Object instance. |
| getVolume |
Returns an integer value, indicating the current volume level for the Music Object instance. |
| General State |
| getInfo |
Returns a string value, indicating some information about an RMF file that is currently loaded into the Music Object instance. |
| Callbacks |
| addCallbackHandler |
Lets you add a callback handler for a specified instance callback. |
| onAudibleStateChange |
Lets you register JavaScript code that is to be executed each time there is a change in the audible state of the Music Object instance. |
| onLoad |
Lets you register JavaScript code that is to be executed each time the Music Object instance completes loading in a file. |
| onMetaEvent |
Lets you register the function to be executed each time the Music Object instance encounters a meta event while playing an RMF or MIDI file. |
| onOutputVolumeChange |
Lets you register JavaScript code that is to be executed each time there is a change in the Music Object instance's output volume. |
| onPause |
Lets you register JavaScript code that is to be executed each time the Music Object instance enters the paused state. |
| onPlay |
Lets you register JavaScript code that is to be executed each time the Music Object instance enters the playing state. |
| onReady |
Lets you register JavaScript code that is to be executed for only the first time that the Music Object instance completes loading in its file and becomes ready for scripted control. |
| onStop |
Lets you register JavaScript code that is to be executed each time the Music Object instance enters the stopped state. |
|
|
MusicObject 2.0 introduced a new concept in Beatnik authoring and addressed many of the issues with cross-browser authoring. One of the significant changes in interactive authoring for Beatnik is that the author no longer embeds players into an HTML page with explicit HTML code, but instead uses the magicEmbed, stubEmbed, and preloadEmbed methods of the Music Object instance. The embedding methods will write the appropriate HTML into the page, depending on what browser the user has. In the case of Netscape Navigator, the embedding methods would write the HTML for a plug-in EMBED tag. And for Microsoft's Internet Explorer, the embedding methods would write the HTML for an ActiveX control OBJECT tag. The embedding methods also perform other useful steps needed in order to link a player instance with a Music Object instance.
The magicEmbed method is the standard way to embed a player instance in an HTML page, so that the player instance can be controlled using the Music Object API.
Using this method is different to a pure HTML approach and requires you to create a SCRIPT block at the position in the HTML document where you would like to embed the player. You then enclose the call to the magicEmbed method within this SCRIPT block. The magicEmbed method takes care of some of the nasty little details for the author, such as the connection between the player instance and its associated Music Object instance. magicEmbed also sets up logical defaults for certain of the player's attributes so the author does not need to specify these. The magicEmbed method takes a string as a parameter - this string representing the EMBED tag that you would normally place in the HTML if you were only authoring for non-interactive music. In this string, it is also not necessary to specify the "<EMBED " text that opens the EMBED tag, nor is it necessary to use ">" to close the EMBED tag. For example, consider the following before-and-after example:
<EMBED
SRC="my-file.rmf"
TYPE="audio/rmf"
WIDTH=144
HEIGHT=60
PLUGINSPAGE="http://www.beatnik.com/to/?player"
>
|
<SCRIPT LANGUAGE=JavaScript><!-- //
myMusicObject.magicEmbed ('SRC="my-file.rmf" WIDTH=144 HEIGHT=60');
// --></SCRIPT>
|
Some things to note
- In the 'AFTER' example shown above, it is assumed that the author has already created the Music Object instance called 'myMusicObject'. The full template is explained in greater detail in the section Starting to use Music Object.
- Notice how, in the magicEmbed method, single quotes are used to enclose the EMBED tag string. This is because the EMBED tag itself may contain double quotes that enclose some of the attribute values, such as the SRC attribute.
- Notice how the TYPE and PLUGINSPAGE attributes are no longer in the EMBED tag that is passed to magicEmbed. This is because the magicEmbed sets up appropriate defaults for these attributes and it is not necessary for the author to specify them.
Authors that are coming from a background of developing for Internet Explorer and using ActiveX controls may find it curious to use the EMBED tag syntax to create a player instance that may end up being an ActiveX control if the user is browsing with IE. The rationale behind this approach is that many early Beatnik authors have been authoring for the Beatnik Plug-in for Netscape, simply because there was no ActiveX control available initially. Much of the Beatnik content is therefore still authored for a plug-in and the magicEmbed method offers an easy upgrade path for early developers because all they have to do is move their HTML EMBED tags into a JavaScript magicEmbed method. It is also beneficial to put forward only one embedding syntax for Beatnik so that authors do not need to be concerned with browser issues.
The magicEmbed method performs the following useful steps
- automatically sets "audio/rmf" as the default value for the TYPE attribute. The user can still override this by specifying a value for the TYPE attribute, but when the TYPE is set to "audio/rmf" the author can always ensure that the browser will use Beatnik to handle file types that may otherwise be handled by another plug-in (such as QuickTime handling MIDI, or Yamaha MIDplug handling MIDI, or LiveAudio handling WAV files, etc.).
- automatically sets the PLUGINSPAGE attribute's value so that users of Netscape Navigator who do not have the Beatnik Plug-in installed will go to the download page on the Beatnik Web site.
- automatically sets the ONREADY attribute's value, specifying a callback function that links the player instance with the Music Object instance. Authors no longer need to be concerned with the mechanics behind ONREADY.
- automatically sets the NAME attribute's value, specifying a name that links the player instance with the Music Object instance. Authors no longer need to understand the naming scheme that connects a player instance with its associated Music Object instance.
- automatically sets the default values for the WIDTH and HEIGHT attributes. Whereas, before it could lead to problems if the author did not specify a value for WIDTH or HEIGHT, magicEmbed now sets 144 as the default WIDTH and sets 60 as the default HEIGHT. These defaults are still overridden by what the author specifies.
With the new mechanism for embedding truly hidden player instances introduced in Music Object version 3.3, a problem was found with embedding hidden instances in table cells, that would cause intermittent crashes in some 4.x versions of Netscape Navigator. Hidden instances should, therefore, not be embedded within table cells (or any other container elements, for that matter). Hidden instances should only be embedded as top level members of the BODY tag. For more information, consult the section Authoring Issues: Embedding Hidden Instances in Table Cells.

- It is only possible to embed one player instance per Music Object instance.
- Refer to the Embedding Properties reference for a full list of attributes that can be specified in the EMBED tag.
- This method may only be called before the player instance has been embedded.
The preloadEmbed method lets you preload a music file into a hidden player instance, for the purpose of triggering the file to play at a later point.
The preloadEmbed method is similar to stubEmbed in that it is also a convenient short form for embedding a player. It is specifically geared towards the preloading of RMF or other files that are to be triggered as one-shots when a certain user interaction occurs in a page. The preloadEmbed method sets the WIDTH and HEIGHT attributes to 2 and uses the HIDDEN attribute to make the player invisible on the page. It also sets the AUTOSTART attribute to FALSE so that the file doesn't begin playing immediately when a page loads up, but can be triggered by the author's UI scripting. Finally, it sets the LOOP attribute to FALSE, assuming that the UI events to be sonified should only trigger one-shots that do not loop endlessly.
The following before-and-after example shows how preloadEmbed can be used in place of magicEmbed to simplify authoring. Apart from efficiency, the two statements are equivalent.
myMusicObject.magicEmbed (
'SRC="trance.rmf" ' +
'WIDTH=0 ' +
'HEIGHT=0 ' +
'HIDDEN ' +
'AUTOSTART=FALSE ' +
'LOOP=FALSE'
);
|
myMusicObject.preloadEmbed ('trance.rmf');
|
It's important to note that, while the magicEmbed method can take an EmbedLineSTR parameter, the preloadEmbed method does not accept this parameter type and can only accept a FileUrlSTR parameter. An optional additional ExtraEmbedAttributesSTR parameter lets you specify further embed attributes or override the default embed attributes that are set by this method.

- preloadEmbed ( FileUrlSTR , ExtraEmbedAttributesSTR )
This is a variation of the preloadEmbed method that takes an additional ExtraEmbedAttributesSTR string as a parameter. With this parameter, the author can either override the defaults that are set by preloadEmbed, or add additional attribute settings that are not automatically set by the preloadEmbed method.
A case where you might want to use the optional parameter would be if you had to embed an RMF file for the sonification of a button click, but the file was a little too loud for the rest of the page's sonification. In this case, you could specify the additional attribute as follows:
myMusicObject.preloadEmbed ('button-flourish.rmf','VOLUME=70');
|
With the new mechanism for embedding truly hidden player instances introduced in Music Object version 3.3, a problem was found with embedding hidden instances in table cells, that would cause intermittent crashes in some 4.x versions of Netscape Navigator. Hidden instances should, therefore, not be embedded within table cells (or any other container elements, for that matter). Hidden instances should only be embedded as top level members of the BODY tag. For more information, consult the section Authoring Issues: Embedding Hidden Instances in Table Cells.

- It is only possible to embed one player instance per Music Object instance.
- This method may only be called before the player instance has been embedded.
The stubEmbed method lets you preload a stub RMF file into a hidden player instance, specifically for the purpose of playing musical notes through that instance.
The stubEmbed method is an authoring shortcut used when an author wishes to embed a hidden player for the purposes of sonifying the user interface of a page. Embedding of a stub file is a technique used often when sonifying the user's interactions on an HTML page with musical notes or Groovoids.
Essentially, the stubEmbed method calls the magicEmbed method with preset values for the WIDTH, HEIGHT, HIDDEN, AUTOSTART, and LOOP attributes. It is assumed that the author does not wish the UI sonification player to have a visible control panel, and so both the WIDTH and HEIGHT are set to 2 pixels, and the HIDDEN attribute is present. Also, it is assumed that the player instance is possibly to be used for note playing as well as Groovoid playing. Since notes can only be played to Beatnik while a music file is being played, the player is therefore embedded with the AUTOSTART and LOOP attributes both set to TRUE. This way, the player will always be in play mode and the author will be able to send playNote and noteOn messages.
The following before-and-after example shows how the embedding of a stub file can be simplified using the stubEmbed method rather than using the magicEmbed method. Apart from efficiency, the two statements are equivalent.
myMusicObject.magicEmbed (
'SRC="stub.rmf" ' +
'WIDTH=0 ' +
'HEIGHT=0 ' +
'HIDDEN ' +
'AUTOSTART=TRUE ' +
'LOOP=TRUE'
);
|
myMusicObject.stubEmbed ('stub.rmf');
|
It's important to note that, while the magicEmbed method can take an EmbedLineSTR parameter, the stubEmbed method does not accept this parameter type and can only accept a FileUrlSTR parameter. This method does also not accept the optional ExtraEmbedAttributesSTR parameter that the preloadEmbed method accepts.
With the new mechanism for embedding truly hidden player instances introduced in Music Object version 3.3, a problem was found with embedding hidden instances in table cells, that would cause intermittent crashes in some 4.x versions of Netscape Navigator. Hidden instances should, therefore, not be embedded within table cells (or any other container elements, for that matter). Hidden instances should only be embedded as top level members of the BODY tag. For more information, consult the section Authoring Issues: Embedding Hidden Instances in Table Cells.

- If no stub file URL is specified, the default is 'stub.rmf' and so, if the file 'stub.rmf' is located in the same directory as the HTML page that you are authoring, it is not necessary to specify a stub file URL.
- It is only possible to embed one player instance per Music Object instance.
- This method may only be called before the player instance has been embedded.
|
Song Control & Player Properties
|
The methods below carry out specific actions and do not return values indicating the success of the operation. They may, therefore, not be used in assignments or conditional statements.
The doMenuItem method lets you emulate the user-selection of one of the control panel's pop-up menu options.
The doMenuItem method behaves exactly the same as if the user had actually selected that option. This method takes a string parameter, representing the name of the menu option you wish to trigger. The names for the menu options are not always the same as the text that appears for the menu options. This is described in greater detail in the definition for the MenuItemNameSTR parameter.

- The menu item name parameter is not case-sensitive.
- This method may be called anytime after the Music Object instance enters the ready state.
The endVolumeFade method lets you terminate any volume fade that is currently in progress for a Music Object instance. If there is no volume fade in progress, then this method will have no effect.

- This method should only be called while the Music Object instance is playing.
The fadeTo method lets you fade the overall playback volume of the Music Object instance from its current volume level to a new specified volume level, over the specified amount of time.


- If the Music Object instance is not currently playing or is in a paused state, this method will have no effect.
- This method should only be called while the Music Object instance is playing.
The fadeVolume method lets you fade the overall playback volume of the Music Object instance from a specified starting volume to a specified ending volume over a specified amount of time.
The fadeVolume method is a superset of the fadeTo method, but allows greater flexibility in control over the volume fade. In addition to specifying starting and ending volumes, you can also specify callbacks that are to be executed as part of the volume fade. The fade end callback lets you specify a callback that is to be executed when the fade has completed. And the fade advance callback lets you specify a callback to be executed for each time that the volume is adjusted during the course of the fade. Both these callbacks are helpful for synchronizing events within an HTML page to a fade that has been initiated.

- When a value of null is specified for the StartVolumeLevel parameter, then the instance's current volume setting is used as the starting volume for the fade.
- When a value of null is specified for the EndVolumeLevel parameter, then the fade will end at volume 0 (silence).
- When a value of null is specified for the FadeBOOL or FadeTimeMsINT parameter, then the fade will have a default duration of 1 second (1000ms), which is equivalent to specifying true or 1000 as a value for this parameter.
- When a value of null is specified for the FadeEndCallback parameter, no callback will be executed when the fade reaches its conclusion.
- When a value of null is specified for the FadeStepCallback parameter, no callback will be executed each time the volume level is updated throughout the course of a fade.

- fadeVolume ( StartVolume0to100 , EndVolume0to100 , FadeBOOLorFadeTimeMsINT , FadeEndCallbackFunctionorJavaScriptSTR )
When no FadeStepCallback value is specified, no callback will be executed each time the volume level is updated throughout the course of a fade.
- fadeVolume ( StartVolume0to100 , EndVolume0to100 , FadeBOOLorFadeTimeMsINT )
When no FadeEndCallback value is specified, no callback will be executed when the fade reaches its conclusion.
- fadeVolume ( StartVolume0to100 , EndVolume0to100 )
When no FadeBOOL or FadeTimeMsINT parameter is specified, the fade will have a default duration of 1 second (1000ms), which is equivalent to specifying true or 1000 as a value for this parameter.

- If the Music Object instance is not currently playing or is in a paused state, this method will have no effect.
- This method should only be called while the Music Object instance is playing.
The getAutostart method returns the autostart property of the Music Object instance.
The autostart property can be set initially using the AUTOSTART embedding property, or set subsequently using the setAutostart method.

- This method may be called anytime after the Music Object instance enters the ready state.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getFileSize method returns the size of the currently loaded file, measured in bytes.
|
FileSizeBytesINT |
Because the value returned by this method is measured in bytes, in order to calculate the KiloByte (Kb) size of the file, you would divide the value returned by 1024. And if you wished to express the file size in MegaBytes (Mb), then you would divide the value returned by 1048576 (1024 x 1024). The following two functions will do the conversions for you...
function bytesToKb (bytes) {
return bytes / 1024;
}
function bytesToMb (bytes) {
return bytes / 1048576;
}
|

- This method should only be called after the Music Object instance has loaded in its file.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getPanelDisplay method returns a string value, indicating the Music Object instance's current control panel display type.
The control panel's display type can be set initially using the DISPLAY embedding property, or subsequently via scripting using the setPanelDisplay method.

- For full details on the available control panel layouts, consult Control Panel Layouts.
- See also setPanelDisplay
- This method may be called anytime after the Music Object instance enters the ready state.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getPanelMode method returns a string value, indicating the Music Object instance's current control panel mode.
The control panel's mode can be set initially using the MODE embedding property, or subsequently via scripting using the setPanelMode method.

- For full details on the available control panel layouts, consult Control Panel Layouts.
- See also setPanelMode
- This method may be called anytime after the Music Object instance enters the ready state.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getPlayLength method returns the playing duration of the currently loaded file, measured in milliseconds.
|
PlayLengthMsINT |
This method is useful when one wishes to queue events to occur when a file has reached its end. One would set a JavaScript timeout at the same moment that a play instruction is sent to the file, as follows: setTimeout ('endOfFileFunction ()',myMusicObject.getPlayLength ()); myMusicObject.play ();. Another application would be to start straight from the middle (halfway mark) of a song by using the expression myMusicObject.setPosition (Math.round (myMusicObject.getPlayLength () / 2));

- This method should only be called after the Music Object instance has loaded in its file.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getPosition method returns an integer value, indicating the currently playing file's song position. Song position is measured in milliseconds from the beginning of a file.
Song position can also be set using the setPosition method.

- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
- This method is only supported for linear audio files (eg. WAV, AIFF, AU) in Beatnik Player versions 2.2 and higher.
The pause method lets you pause the file that is currently being played through the Music Object instance, so that it may be resumed later using either the pause or play methods.
If a player is in a playing state when this method is called then the player will enter a paused state. If the player is in a paused state when this method is called then the player will re-enter a playing state, resuming playback at the position where it was paused. When a player is in a paused state, the isPaused method will return a value of true. If the player is in a stopped state, then calling the pause method will have no affect.


- This method should only be called after the Music Object instance has loaded in its file.
The play method lets you start a file playing that is currently loaded into a Music Object instance, load or play a different music file than the file that is currently loaded by specifying a file URL, or resume playback of a Music Object instance that is in a paused state.
When used with no parameters, the play method will start the Music Object instance playing whichever file it currently has loaded. If the instance is already playing, then this method will have no affect and the instance will continue playing - the instance will not restart the file it is playing from the beginning. If a Music Object instance already has a file loaded, then to restart the file playing each time a certain event occurs, simply precede the play () instruction with a stop () instruction, as in myMusicObject.stop (); myMusicObject.play ();. If an instance is currently busy loading in a music file, then a play () instruction will have no affect. If the Music Object instance has been put into a paused state using the pause method, then a play () instruction will make the instance resume playing.

- play ( LoopingBOOL , FileUrlSTR )
When used with a looping value and URL, play will fetch that file from the URL and, if the current AUTOSTART property is true, will start playing it once it has finished loading. The LoopingBOOL parameter will determine whether the file will loop or not once it reaches the end. The FileUrlSTR parameter follows the same syntax as a URL used in the SRC embedding property.
- play ( LoopingBOOL , GroovoidNameSTR )
Behaves the same as the variation above, but allows you to specify a Groovoid name in place of a file URL.
- play ( LoopingBOOL )
When used with only a parameter for looping, play will start playing the currently loaded file. This is useful for a file that is loaded when the player is first embedded but doesn't play automatically because the AUTOSTART embedding property is set to false. The file can then be triggered to play through a user's interaction by using this form of the play method.
- play ( FileUrlSTR )
When only a file URL is specified, play will fetch that file from the URL and, if the current AUTOSTART property is true, will start playing it once it has finished loading. The file will not loop when it has completed playing through.
- play ( GroovoidNameSTR )
Similar to the variation above, this form of the play method lets you to specify a Groovoid name in place of a file URL. When the Groovoid plays, its looping state will be determined automatically based upon the type of Groovoid specified. All Groovoids belonging to the "Background-" group will automatically be looped, and all other Groovoids will not be looped.

- When a string value of auto is specified for the LoopingBOOL parameter, then the Music Object instance will automatically loop Groovoids that belong to the "Background-" group of Groovoids, but will not loop other Groovoids or files specified using the FileUrlSTR parameter. For example, play ("auto","Background-Dubby") will loop, whereas play ("auto","Fanfare-CorpSting1") and play ("auto","jungle.rmf") will not loop.

- This method may be called anytime after the Music Object instance enters the ready state.
The setAutostart method lets you set the autostart property of the Music Object instance.
The autostart property can also be set initially using the AUTOSTART embedding property. The autostart property will affect all new files that are played using the play method. The current value of the autostart property can be obtained using the getAutostart method.

- This method may be called anytime after the Music Object instance enters the ready state.
The setEndTime method lets you specify the position within the currently loaded file where you would like playback to stop automatically.
The effect of this method is to override the file's natural end position. See also the companion setStartTime method.

- This method may be called anytime after the Music Object instance enters the ready state.
- This method is only supported for linear audio files (eg. WAV, AIFF, AU) in Beatnik Player versions 2.2 and higher.
The setLoop method lets you set the loop status of the Music Object instance.
This method can be used after a file has already been loaded and effectively overrides any loop status which may have been set using the LOOP attribute in the <EMBED> tag. Loop state can be obtained through the Music Object using the getLoop method.

- This method may be called anytime after the Music Object instance enters the ready state.
The setPanelDisplay method lets you set the control panel display type of the Music Object instance.
The two available types are 'SONG' and 'SYSTEM', and correspond to the accepted values for the DISPLAY embedding property. An invalid value for the PanelDisplaySTR parameter will be ignored and the control panel will stay in its current state.

- The PanelDisplaySTR parameter is not case-sensitive.
- For full details on the available control panel layouts, consult Control Panel Layouts.
- See also getPanelDisplay
- This method may be called anytime after the Music Object instance enters the ready state.
The setPanelMode method lets you set the control panel mode of the Music Object instance.
The three available modes are 'METERS', 'SCOPE', and 'COPYRIGHT', and correspond to the accepted values for the MODE embedding property. An invalid value for the PanelModeSTR parameter will be ignored and the control panel will stay in its current state. Valid values are dependent on the control panel's current display type (see setPanelDisplay). For instance, if the current display type is 'SYSTEM', only 'METERS' and 'SCOPE' are appropriate values for the PanelModeSTR parameter. And, if the current display type is 'SONG', then only 'COPYRIGHT' is appropriate as a value for the PanelModeSTR parameter.

- The PanelModeSTR parameter is not case-sensitive.
- For full details on the available control panel layouts, consult Control Panel Layouts.
- See also getPanelMode
- This method may be called anytime after the Music Object instance enters the ready state.
The setPosition method lets you jump to a new position in the music file that is currently being played by the Music Object instance. Song position is measured in milliseconds from the beginning of a file.
Song position can be obtained using the getPosition method.
ISSUES
- There is an issue with the setPosition method, where all performance settings that have been modified by JavaScript authoring are reset after a setPosition call has been performed. In other words, if you have used scripting to mute or solo channels or tracks, these modifications are reset after setPosition has been performed and the music file plays back with its original internal settings. Beatnik Inc. considers this a player bug and we are working on fixing this problem for a future release of the player.
- With versions of the Beatnik Player earlier than 2.2, if you have the Music Object instance in a paused state at the time that you use the setPosition method, then the instance will jump to the new position you specify and will start playing - it will not remain in the paused state. This undesirable behavior was fixed with Beatnik Player version 2.2.

- This method should only be called while the Music Object instance is playing.
- This method is only supported for linear audio files (eg. WAV, AIFF, AU) in Beatnik Player versions 2.2 and higher.
The setStartTime method lets you specify the position in an RMF or MIDI file, where you would like playback to start.
The effect of this method is to override the song's natural beginning position.
IMPORTANT : Due to a problem with the Player implementation of this method, any start time that you set using this method is only observed when a file is started by the user clicking on the Player control panel's play button, and not when a file is started using the Music Object play method. As a result, this method currently has limited usefulness. This problem will be fixed in a future release of the Beatnik Player.
See also the companion setEndTime method.

- This method may be called anytime after the Music Object instance enters the ready state.
- This method is only supported for linear audio files (eg. WAV, AIFF, AU) in Beatnik Player versions 2.2 and higher.
The setVolume method lets you set the overall playback volume of the Music Object instance.
Using the setVolume method has a different effect to setting the individual volumes for MIDI channels in a music file, which can be done using the setController method.

- setVolume ( VolumeScalarNameSTR , Volume0to100 )
When the Volume0to100 parameter is preceded by a VolumeScalarNameSTR parameter, then the setVolume method will set the volume level of the custom volume scalar specified by the VolumeScalarNameSTR parameter. If a custom volume scalar by the name specified in the VolumeScalarNameSTR parameter does not already exist, then a new custom volume scalar by that name will be created and will be initialized to the value specified by the Volume0to100 parameter. For more information on volume scalars, see the section Important Concepts: Custom Volume Scalars.
- setVolume ( VolumeScalarNameSTR , -1 )
When the setVolume method is used to set the volume of a custom volume scalar and the value -1 is specified in place of the Volume0to100 parameter, then the volume scalar specified by the VolumeScalarNameSTR parameter will effectively be removed. If there is no existing volume scalar matching the name specified by the VolumeScalarNameSTR parameter, then the setVolume method will have no effect. For more information on volume scalars, see the section Important Concepts: Custom Volume Scalars.
- setVolume ( )
When no parameters are specified for the setVolume method, the method has the effect of updating the volume of the Music Object instance's player to take into account the values of all the instance's custom volumes scalars. This is particularly useful if the custom volume scalars are going to be set manually by accessing elements of the instance's volumeScalars array, rather than by using the variation of the setVolume method that takes a VolumeScalarNameSTR parameter. For more information on volume scalars, see the section Important Concepts: Custom Volume Scalars.

- This method may be called anytime after the Music Object instance enters the ready state.
The stop method lets you stop any file that is currently playing through the Music Object instance.
Stopped files may not be resumed with the pause method. To pause files so that they may be resumed, use the pause method.

- stop ( FadeBOOL )
When used with a boolean true value, will fade out and then stop the Music Object instance, if it is currently playing. Used with a boolean false value, will have the same effect as stop with no parameters. If you invoke a faded stop on a file just before linking to a new page, that will not result in a music fade over the page change unless you place the music file in a persistent frame, or delay the link to the next page until the fade is complete using JavaScript. Otherwise the file will be abruptly cut short as the player gets unloaded.
- stop ( FadeTimeMsINT )

- This method should only be called after the Music Object instance has loaded in its file.
The noteOff method lets you turn off a note that is currently playing through the Music Object instance.
In order to specify the exact note to be turned off, it is necessary to specify the MIDI channel and note number values used to switch the note on. If no note is currently playing with the specified properties, this method has no effect. noteOff may also be used to turn off notes which have been turned on using the playNote method.

- noteOff ( MidiChannel1to16 , NoteNameSTR )
This variation allows you to specify the MIDI note by a NoteNameSTR instead of a MIDI note number.
- noteOff ( MidiChannel1to16 )
By only specifying a MIDI channel number, the noteOff method will switch off all notes that are currently playing on the specified MIDI channel. This only applies, however, to notes that were turned on using Music Object's noteOn method, and does not apply to notes that were turned on from inside an RMF or MIDI file. The method is still useful, however, for user interface sonification that is done entirely through scripted note playing.

- This method should only be called while the Music Object instance is playing.
- See the demo for this method.
The noteOn method lets you start a note playing on a specified MIDI channel number, with a specified note number and velocity.
The note turned on using this method will continue to be sustained indefinitely unless switched off using the noteOff method.

- noteOn ( MidiChannel1to16 , NoteNameSTR , Velocity0to127 )
This variation allows you to specify the MIDI note by a NoteNameSTR instead of a MIDI note number.
- noteOn ( MidiChannel1to16 , BankNumber0to2 , ProgramNumber0to255 , NoteNumber0to127 , Velocity0to127 )
This variation of the noteOn method can accept a BankNumber0to2 and ProgramNumber0to255 parameter as well. This makes it easy for authors to directly play a sound from a specific bank and program, based on events such as ONMOUSEOVER and ONCLICK.
- noteOn ( MidiChannel1to16 , BankNumber0to2 , ProgramNumber0to255 , NoteNameSTR , Velocity0to127 )
Behaves the same as the previously shown version of this method, excepting that this version allows you to specify the MIDI note by a NoteNameSTR instead of a MIDI note number.

- This method should only be called while the Music Object instance is playing.
- See the demo for this method.
The playNote method lets you play a note on the specified MIDI channel, of the specified note number, velocity, and duration.
The NoteDurationMsINT parameter is measured in milliseconds (1/1000th of a second). Notes which are started using playNote may also be switched off using noteOff, even before their duration has expired. To do this, it is necessary to target the note using the correct MIDI channel, note number, and velocity used in the initial playNote call.

- playNote ( MidiChannel1to16 , NoteNameSTR , Velocity0to127 , NoteDurationMsINT )
Behaves the same as the previously shown version of this method, excepting that this version allows you to specify the MIDI note by a NoteNameSTR instead of a MIDI note number.
- playNote ( MidiChannel1to16 , BankNumber0to2 , ProgramNumber0to255 , NoteNumber0to127 , Velocity0to127 , NoteDurationMsINT )
This variation of the playNote method can also accept the BankNumber0to2 and ProgramNumber0to255 parameters. This makes it easy for authors to directly play a sound from a specific bank and program, based on events such as ONMOUSEOVER and ONCLICK.
- playNote ( MidiChannel1to16 , BankNumber0to2 , ProgramNumber0to255 , NoteNameSTR , Velocity0to127 , NoteDurationMsINT )
Behaves the same as the previously shown version of this method, excepting that this version allows you to specify the MIDI note by a NoteNameSTR instead of a MIDI note number.

- This method should only be called while the Music Object instance is playing.
- See the demo for this method.
|
Realtime Control Of Files
|
The setChannelMute method lets you mute or unmute the specified MIDI channel, based upon the value of the MuteStateBOOL parameter.
Using a value of true for the MuteStateBOOL parameter will mute a channel, and using false will unmute a channel. A channel's current mute status can be obtained by using the getChannelMute method. When a value of 0 is specified for the MidiChannel0to16 parameter, then the mute state specified by the MuteStateBOOL parameter is applied to all 16 MIDI channels.

The setChannelSolo method lets you solo or unsolo the specified MIDI channel, based upon the value of the SoloStateBOOL parameter.
Using a value of true for the SoloStateBOOL parameter will solo a channel and using false will unsolo a channel. A channel's current solo status can be obtained by using the getChannelSolo method. When a value of 0 is specified for the MidiChannel0to16 parameter, then the solo state specified by the SoloStateBOOL parameter is applied to all 16 MIDI channels.

The setController method lets you set a value for a specified MIDI controller on a specified MIDI channel.
When a value of 0 is specified for the MidiChannel0to16 parameter, then the specified MIDI controller will be set to the specified controller value on all 16 MIDI channels.
MIDI Event Queue
The setController method has the effect of adding a continuous controller MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getController method to query the value of a specific MIDI controller that was just "set" using the setController method may not return the value that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.

The setMonophonic method lets you set the monophonic state of a specified MIDI channel, based upon the value of the MonophonicStateBOOL parameter.
Using a value of true for the MonophonicStateBOOL parameter will set the channel as being monophonic, and using false will restore it to being polyphonic. A channel's current monophonic status can be obtained by using the getMonophonic method. Setting a channel as being monophonic only affects the playing of notes through authoring and does not affect notes being played from an RMF or MIDI file. It is, however, very useful in sonifying a user's interaction with a Web page. For instance, one can prevent graphics that are sonified with mouseover sounds from stacking up a cacophony of notes by setting a certain channel as being monophonic and then making that channel play the mouseover notes.

The setProgram method lets you issue a program change message to the specified MIDI channel with the specified program number.
MIDI Event Queue
The setProgram method has the effect of adding a program change MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getProgram method to query the program for a specific MIDI channel that was just "set" using the setProgram method may not return the program that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.


The setTempo method lets you set the tempo (playback speed) of the music file that is playing through the Music Object instance.
Because the setTempo method sets the tempo to a new absolute value which is not relative to the current playing tempo, in order to set a playback tempo that is relative to the current tempo you should use the getTempo method first to poll the current playing tempo, then use JavaScript to modify that value (eg. add to it or multiply it by a factor), and then finally call the setTempo method with that new modified value, as in the statement...
myMusicObject.setTempo (myMusicObject.getTempo () + 10)
|
The setTempo method should only be used while a song is playing and has no effect if a song is stopped. Playing automatically resets any tempo which was set while a song was stopped to the song's internal tempo setting. Tempo is also reset each time the Beatnik Player loops a music file as a result of the LOOP attribute being set to true. This may be a problem when creating certain types of interactive musical experiences. As a workaround for this, you can insert LOOPSTART and LOOPEND marker events into the file to ensure that an RMF or MIDI file loops indefinitely without resetting tempo (and other settings). This internal looping mechanism is documented in more detail in the Beatnik Editor documentation. Add the LOOPSTART marker a fraction after the beginning of the file and right after any initialization events so that these also don't get re-triggered. If the LOOPSTART point is only a few ticks after the beginning of the file, then you won't even notice the tiny amount that is lost from the playback time.

- This method should only be called while the Music Object instance is playing.
The setTrackMute method lets you mute or unmute the specified track, based upon the value of the MuteStateBOOL parameter.
Using a value of true for the MuteStateBOOL parameter will mute a track, and using a value of false will unmute a track. A track's current mute status can be obtained by using the getTrackMute method.

- When a value of 0 is specified for the TrackNumber0to64 parameter, then all tracks will be muted / unmuted by this method.

- This method should only be called while the Music Object instance is playing.
The setTrackSolo method lets you solo or unsolo the specified track, based upon the value of the SoloStateBOOL parameter.
Using a value of true for the SoloStateBOOL parameter will solo a track, and using a value of false will unsolo a track. A track's current solo status can be obtained by using the getTrackSolo method.

- When a value of 0 is specified for the TrackNumber0to64 parameter, then all tracks will be soloed / unsoloed by this method.

The setTransposable method lets you set whether or not the specified MIDI channel in an RMF or MIDI file is transposable.
By default, all MIDI channels excepting the percussion channel (channel 10) are transposable, unless set otherwise using this method. If a MIDI channel is transposable, then the musical notes playing on that channel will be affected / offset by the transposition setting for the Music Object instance (as set using the setTranspose method).
On the other hand, if a MIDI channel is not transposable, then the transposition setting for the instance will have no affect on the musical notes that play through that channel. This is particularly useful for RMF files that contain MIDI channels that are playing custom instrument drum loops. If such channels were to be transposed along with the other channels in the music file, then the tempo of the drum loops would be affected as the drum loop samples are pitch-shifted, creating undesirable chaos in the overall rhythm of the music.
Another useful application for the non-transposable state is the case where a MIDI channel is playing percussion instruments in pitched mode using NRPN640 (see the Beatnik Editor documentation) to achieve "talking drum" effects. It is most likely that such percussion effects will not be in the specific key of the melodic elements of the musical arrangement, and transposing them would produce inappropriate results. By setting such MIDI channels to be non-transposable, problems like this can be avoided when transposing the music using the setTranspose method.
You can toggle the transposable state for a specific MIDI channel by using the getTransposable method in conjunction with the setTransposable method, as in the example myMusicObject.setTransposable (!myMusicObject.getTransposable (13));.

- This method should only be called while the Music Object instance is playing.
The setTranspose method lets you set the pitch transposition of the file that is currently playing through the Music Object instance. Pitch transposition is measured in musical half steps.
The pitch transposition set by this method is not a cumulative value. ie. If you use the statement setTranspose (12), the file will transpose up by a complete octave but, if you execute that statement again, the file will not transpose up again by an octave but simply stay transposed by one octave. So, it also follows that if you use the statement setTranspose (0), then the file will return to playing at its normal pitch.

- This method may be called anytime after the Music Object instance enters the ready state.
|
Obtaining Playback State Information
|
All of the methods listed below return values that indicate state information about the Music Object instance. They may be used in assignment statements, conditional statements, or expressions. The type of the value returned by each method (ie. string, integer, or boolean) is specified in the description for each method.
The isPaused method returns a boolean value, indicating the current paused state of the Music Object instance.
|
PausedBOOL
true = is paused
false = is not paused (could be playing or stopped)
|
The isPaused method returns a value of true if the instance is currently in a paused state, or a value of false if the instance is in a playing or stopped state. See also the isPlaying method.

- This method may be called anytime after the Music Object instance enters the ready state.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The isPlaying method returns a boolean value, indicating the current playing state of the Music Object instance.
|
PlayingBOOL
true = is playing
false = is not playing (could be paused or stopped)
|
The isPlaying method returns a value of true if the instance is currently in a playing state, or a value of false if the instance is in a paused or stopped state. See also the isPaused method.
There is no dedicated method to determine if an instance is in a stopped state, but you could easily deduce if an instance is stopped by using the isPlaying and isPaused methods in combination. If an instance is not in the playing state and is also not in the paused state, then it must be in the stopped state. The following custom function takes a Music Object instance as a parameter and returns a boolean value indicating the instance's stopped state...
function isStopped (musicObjectRef) {
return !musicObjectRef.isPlaying () && !musicObjectRef.isPaused ();
}
|
One would call the above function passing the Music Object instance as a parameter, as in the statement if (isStopped (myMusicObject)) {updateButtonsDisplay ()}.

- This method may be called anytime after the Music Object instance enters the ready state.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getChannelMute method returns a boolean value, indicating the current mute status of the specified MIDI channel.
A return value of true indicates that the channel is muted, and a value of false indicates that it is not muted. A channel's mute status can be set using the setChannelMute method.

- For a more comprehensive explanation of mute and solo, consult the section Mute and Solo, and How They Interact with Each Other.
- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getChannelSolo method returns a boolean value, indicating the current solo status of the specified MIDI channel.
A return value of true indicates that the channel is soloed, and a value of false indicates that it is not soloed. A channel's solo status can be set using the setChannelSolo method.

- For a more comprehensive explanation of mute and solo, consult the section Mute and Solo, and How They Interact with Each Other.
- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getController method returns an integer value, indicating the current value of the specified MIDI controller on the specified MIDI channel.
Controller values can be set using the setController method.
MIDI Event Queue
The setController method has the effect of adding a continuous controller MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getController method to query the value of a specific MIDI controller that was just "set" using the setController method may not return the value that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.

- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getLoop method returns a boolean value, indicating the current loop status of the Music Object instance.
Loop state can be set either in the HTML with the LOOP attribute, or via scripting using the setLoop method.

- This method may be called anytime after the Music Object instance enters the ready state.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getMonophonic method returns a boolean value, indicating the monophonic state of the specified MIDI channel.
|
MonophonicStateBOOL
true = is monophonic
false = is not monophonic (ie. is polyphonic)
|
A return value of true indicates that the specified MIDI channel is in monophonic mode, while a value of false indicates that the channel is in polyphonic mode. A channel's monophonic status can be set using the setMonophonic method.

- This method may be called at any time.
The getOutputVolume method returns an integer value, indicating the current overall output volume of the Music Object instance.
The value returned by the getOutputVolume method may be different to the value returned by the getVolume instance method, and will depend on the state of any custom volume scalars that may be registered for the instance. For a better understanding of how custom volume scalars work, consult the section Important Concepts: Custom Volume Scalars.

- This method may be called at any time.
- Compare to the getVolume instance method.
- See also the setVolume instance method.
The getProgram method returns an integer value, indicating the program number that is currently selected for the specified MIDI channel.
A channel's program number is set initially via program change events that occur within an RMF or MIDI file, but can also be set via scripting using the setProgram method.
MIDI Event Queue
The setProgram method has the effect of adding a program change MIDI event to the audio engine's MIDI event queue, to be processed after all other events already in the queue have been processed. As a result of this, calling the getProgram method to query the program for a specific MIDI channel that was just "set" using the setProgram method may not return the program that was just set. For more information, consult the section Important Concepts: MIDI Event Queue.

- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getTempo method returns an integer value, indicating the current tempo (playback speed) of the file that is playing through the Music Object instance. Tempo is measured in BPM (beats per minute).
Tempo is set initially from a value that is stored within an RMF or MIDI file, but can also be set via scripting using the setTempo method.

- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getTrackMute method returns a boolean value, indicating the current mute status of the specified track.
A return value of true indicates that the specified track is muted, and a value of false indicates that it is not muted. A track's mute status can be set using the setTrackMute method.

- For a more comprehensive explanation of mute and solo, consult the section Mute and Solo, and How They Interact with Each Other.
- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getTrackSolo method returns a boolean value, indicating the current solo status of the specified track.
A return value of true indicates that the specified track is soloed, and a value of false indicates that it is not soloed. A track's solo status can be set using the setTrackSolo method.

- For a more comprehensive explanation of mute and solo, consult the section Mute and Solo, and How They Interact with Each Other.
- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getTransposable method returns a boolean value, indicating whether or not the specified MIDI channel will be affected by the Music Object instance's transposition value (which is set using the setTranspose method).
|
TransposableBOOL
true = is transposable
false = is not transposable
|
When a value of false is returned by this method, it indicates that the channel is not transposable, and when a value of true is returned, it indicates that the channel is transposable. See also the setTransposable method.

- This method should only be called while the Music Object instance is playing.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getTranspose method returns an integer value, indicating the current pitch transposition of the Music Object instance. Pitch transposition is measured in musical half steps.
|
MusicalIntervalsINT |
Transposition can be set using the setTranspose method.

- This method may be called anytime after the Music Object instance enters the ready state.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
The getVolume method returns an integer value, indicating the current volume level for the Music Object instance.
Volume can be set initially using the VOLUME embedding property, but can also be set via scripting using the setVolume method.

- getVolume ( VolumeScalarNameSTR )
When a VolumeScalarNameSTR parameter is specified, then the getVolume method will return the current value of the custom volume scalar specified by the VolumeScalarNameSTR parameter. If no custom volume scalar by the name specified in the VolumeScalarNameSTR parameter exists, then the getVolume method will return the value null. For more information on volume scalars, see the section Important Concepts: Custom Volume Scalars.

- This method may be called at any time.
The methods listed below return values that indicate general state information. The type of the value returned by each method (ie. string, integer, or boolean) is specified in the description for each method.
The getInfo method returns a string value, indicating some information about an RMF file that is currently loaded into the Music Object instance. The type of information that is returned is determined by the InfoFieldNameSTR parameter.
|
InfoFieldValueSTR |
The InfoFieldNameSTR parameter passed to this method indicates the specific field of an RMF file's song information that is being requested. The possible field names are listed in the definition of the InfoFieldNameSTR parameter. Field names are not case-sensitive.

- A null string will be returned if an invalid field name is specified.
- This method should only be called after the Music Object instance has loaded in its file.
- If the Music Object instance is not in the ready state when this method is called, then the method will return the value null.
Callbacks make it possible to synchronize events in an HTML page with events that occur within music or audio files. For a better understanding of how to use callbacks, consult the section Important Concepts: Callbacks.
The addCallbackHandler method lets you add a callback handler to the stack of callback handlers for a specified instance callback.
Using this method is equivalent to using some of the methods in the Callbacks extension, such as the addOnLoad, addOnMetaEvent, addOnPause, addOnPlay, addOnReady, and addOnStop methods. For instance, the statement myMusicObject.addCallbackHandler ('onPlay','myOnPlayHandler ()') is equivalent to the statement myMusicObject.addOnPlay ('myOnPlayHandler ()'). One thing this method allows is for callback handlers to be dynamically assigned to certain callback types, since one could use a string expression for the InstanceCallbackTypeSTR parameter to determine to which callback type the handler should be added.


The onAudibleStateChange method lets you register JavaScript code that is to be executed each time there is a change in the audible state of the Music Object instance.
Whenever there is a change in the audible state of a Music Object instance, there is a corresponding change in the value of the instance's audible property. So, at the time that the handler for this callback is executed, the current audible state can be obtained by querying the audible instance property. For a clearer understanding of the specific conditions that result in an instance being considered audible or inaudible, consult the reference section for the audible instance property.

- onAudibleStateChange ( HandlerFunction )
- onAudibleStateChange ( null )
When the value null is specified in place of a HandlerJavaScriptSTR or HandlerFunction parameter, then the currently registered handler for this callback is cleared.
- onAudibleStateChange ( )
When no parameter is specified for the onAudibleStateChange method, then the currently registered handler for this callback is cleared.

The onLoad method lets you specify JavaScript code that is to be executed each time the Music Object instance completes loading in a file.
The onLoad callback can be used, for example, to freeze the operation of a sonified Web page until all the sound elements that the page relies upon have fully loaded in.

- onLoad ( HandlerFunction )
- onLoad ( null )
When the value null is specified in place of a HandlerJavaScriptSTR or HandlerFunction parameter, then the currently registered handler for this callback is cleared.
- onLoad ( )
When no parameter is specified for the onLoad method, then the currently registered handler for this callback is cleared.

The onMetaEvent method lets you register the function to be executed each time the Music Object instance encounters a meta event while playing an RMF or MIDI file.
Handler Must be a Function
Unlike other methods that register callback handlers, the onMetaEvent method only accepts a Function parameter type for the callback handler. The function that is registered as a handler for meta event callbacks must expect to receive two string parameters. The first parameter will contain a value of type MetaEventTypeSTR, indicating the type of meta event that has been encountered. The second parameter will contain a string value, indicating the value of the meta event that has been encountered. For instance, if a marker named "Chorus Starts" were encountered, then the first parameter would contain the string value "Marker" and the second parameter would contain the string value "Chorus Starts".
The possible values for the first parameter are:
- GenericText
- Copyright
- Lyric
- Marker
- CuePoint
- Unknown
TrackName events are not currently supported by the Beatnik Player, since it was decided that the sheer volume of these events clumped up at the beginning of RMF and MIDI files may produce too much load on the JavaScript interpreter and may "bring down" the JavaScript code intended to handle meta events.
Define the Handler Function First
It's very important that the function you wish to register as a handler for meta event callbacks be defined before you call the onMetaEvent method. If your handler function is not defined beforehand then your code will produce JavaScript errors and will not work correctly. For example, compare the following two code segments...
myMusicObject = new Music ();
myMusicObject.onMetaEvent (myMetaEventHandler);
function myMetaEventHandler (metaEventType,metaEventValue) {
// some code to handle meta events
}
|
function myMetaEventHandler (metaEventType,metaEventValue) {
// some code to handle meta events
}
myMusicObject = new Music ();
myMusicObject.onMetaEvent (myMetaEventHandler);
|
An Example
In the following hypothetical example, we're assuming that the Music Object instance "myMusicObject" is playing a music file that contains marker events to indicate when the chorus sections start and end. The function myMetaEventHandler is registered as the meta event handler for this instance, using the statement myMusicObject.onMetaEvent (myMetaEventHandler).
//...........................
// more JavaScript code above
function myMetaEventHandler (metaEventType,metaEventValue) {
if (metaEventType == 'Marker') {
if (metaEventValue == 'Chorus Starts') {
// code to SHOW chorus lyrics layer
} else if (metaEventValue == 'Chorus Ends') {
// code to HIDE chorus lyrics layer
}
}
}
myMusicObject = new Music ();
myMusicObject.onMetaEvent (myMetaEventHandler);
// more JavaScript code below
//...........................
|
The function myMetaEventHandler contains conditional code to check for the markers "Chorus Starts" and "Chorus Ends" and to then update the display of the HTML page appropriately. The function myMetaEventHandler may be called many times while the music file is playing for other meta events that are encountered, but because of the conditional "if" statements, the function will only ever do something when a marker event is encountered that has either the value "Chorus Starts" or "Chorus Ends".
The specific code that you would place inside the meta event handler function will depend entirely on the types of events you wish to filter out and act upon. If you wanted, you could write your handler function so that it always does the same thing, regardless of the type or value of meta events encountered. Another possibility would be to write a handler function that always does the same thing, but for only a specific type of meta event. It all depends on the goals of your project.

- onMetaEvent ( null )
When the value null is specified in place of a HandlerFunction parameter, then the currently registered handler for this callback is cleared.
- onMetaEvent ( )
When no parameter is specified for the onMetaEvent method, then the currently registered handler for this callback is cleared.

The onOutputVolumeChange method lets you register JavaScript code that is to be executed each time there is a change in the Music Object instance's output volume.
A change in output volume can occur as a result of...
- a call to the setVolume instance method
- a volume fade initiated by the fadeVolume instance method
- a volume scalar fade initiated by the fadeVolumeScalar instance method
- a ducking process that is triggered, as a result of the instance acting as a ducking slave to another instance that is acting as a ducking master (see the section Music Object Extension - Ducking)
At the time that the handler for this callback is executed, the current output volume can be obtained using the getOutputVolume instance method.

- onOutputVolumeChange ( HandlerFunction )
- onOutputVolumeChange ( null )
When the value null is specified in place of a HandlerJavaScriptSTR or HandlerFunction parameter, then the currently registered handler for this callback is cleared.
- onOutputVolumeChange ( )
When no parameter is specified for the onOutputVolumeChange method, then the currently registered handler for this callback is cleared.

The onPause method lets you register JavaScript code that is to be executed each time the Music Object instance enters the paused state.
A Music Object instance enters the paused state when playback is paused by the user via the pause button on the player's control panel or the "Pause" option in the player's pop-up menu, or if playback is paused via scripting with the pause method.
The onPause callback can be used, for example, to synchronize events that occur within a Web page to the user's control of a music file. For an illustration of this callback in action, consult the tutorial Using Player Callbacks.

- onPause ( HandlerFunction )
- onPause ( null )
When the value null is specified in place of a HandlerJavaScriptSTR or HandlerFunction parameter, then the currently registered handler for this callback is cleared.
- onPause ( )
When no parameter is specified for the onPause method, then the currently registered handler for this callback is cleared.

The onPlay method lets you register JavaScript code that is to be executed each time the Music Object instance enters the playing state.
A Music Object instance enters the playing state when the AUTOSTART property is set to true at the time that the instance completes loading in a file, or if playback is started by the user via the play button on the player's control panel or the "Play" option in the player's pop-up menu, or if playback is started via scripting with the play method.
The onPlay callback can be used, for example, to synchronize events that occur within a Web page to the user's control of a music file. For an illustration of this callback in action, consult the tutorial Using Player Callbacks.

- onPlay ( HandlerFunction )
- onPlay ( null )
When the value null is specified in place of a HandlerJavaScriptSTR or HandlerFunction parameter, then the currently registered handler for this callback is cleared.
- onPlay ( )
When no parameter is specified for the onPlay method, then the currently registered handler for this callback is cleared.

The onReady method lets you register JavaScript code that is to be executed for only the first time that the Music Object instance completes loading in its file and becomes ready for scripted control.
Compare the behavior of this callback to the onLoad callback, which is executed each time that a Music Object instance finishes loading in a new file.

- onReady ( HandlerFunction )
- onReady ( null )
When the value null is specified in place of a HandlerJavaScriptSTR or HandlerFunction parameter, then the currently registered handler for this callback is cleared.
- onReady ( )
When no parameter is specified for the onReady method, then the currently registered handler for this callback is cleared.

The onStop method lets you register JavaScript code that is to be executed each time the Music Object instance enters the stopped state.
A Music Object instance enters the stopped state when the music file it is playing reaches its natural end and stops, or if the player is stopped by the user via the stop button on the player's control panel or the "Stop" option in the player's pop-up menu, or if the player is stopped via scripting with the stop method.
The onStop callback can be used, for example, to synchronize events that occur within a Web page to the user's control of a music file. For an illustration of this callback in action, consult the tutorial Using Player Callbacks.

